import request from './request'

// 用户分页查询公告列表（普通用户）
export const getNoticeList = (params) => {
  return request.get('/notices', { params })
}

// 管理员分页查询公告列表
export const getAdminNoticeList = (params) => {
  return request.get('/notices/admin', { params })
}

// 发布公告
export const createNotice = (data) => {
  return request.post('/notices', data)
}

// 保存草稿
export const saveDraft = (data) => {
  return request.post('/notices/draft', data)
}

// 更新公告
export const updateNotice = (id, data) => {
  return request.put(`/notices/${id}`, data)
}

// 删除公告
export const deleteNotice = (id) => {
  return request.delete(`/notices/${id}`)
}

// 根据ID查询公告详情
export const getNoticeDetail = (id) => {
  return request.get(`/notices/${id}`)
}

// 撤回公告
export const withdrawNotice = (id) => {
  return request.post(`/notices/${id}/withdraw`)
}

// 置顶/取消置顶公告
export const setTopNotice = (id, isTop) => {
  return request.post(`/notices/${id}/top`, null, { params: { isTop } })
}

// 确认阅读公告
export const confirmRead = (id) => {
  return request.post(`/notices/${id}/confirm`)
}

// 批量确认阅读
export const batchConfirmRead = (noticeIds) => {
  return request.post('/notices/batch-confirm', noticeIds)
}

// 获取置顶公告
export const getTopNotices = () => {
  return request.get('/notices/top')
}

// 获取最新公告
export const getLatestNotices = (params) => {
  return request.get('/notices/latest', { params })
}

// 获取未读公告数量
export const getUnreadCount = () => {
  return request.get('/notices/unread-count')
}

// 获取公告统计信息
export const getNoticeStatistics = (id) => {
  return request.get(`/notices/${id}/statistics`)
}

// 获取公告类型选项
export const getNoticeTypes = () => {
  return request.get('/notices/types')
}
